package com.ksy.common.image;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.ViewGroup;

import com.ksy.common.activity.CommonBaseActivity;

import java.util.ArrayList;

/**
 * Created by XXX.
 */

public class ImageShowActivity extends CommonBaseActivity {
    @Override
    protected boolean isShowHeadBar() {
        return false;
    }

    public static void showImages(Context context, ArrayList<String> allImageUrl, int index) {
        Intent intent = new Intent(context, ImageShowActivity.class);
        intent.putExtra("allImageUrl", allImageUrl);
        intent.putExtra("index", index);
        context.startActivity(intent);
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    }

    @Override
    protected boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        ArrayList<String> allImages = (ArrayList<String>) intent.getSerializableExtra("allImageUrl");
        int index = intent.getIntExtra("index", 0);
        ImageShowView imageShowView = new ImageShowView(ImageShowActivity.this);
        imageShowView.setImageSrcClickListener(new ImageShowView.ImageSrcClickListener() {
            @Override
            public void onImageSrcClick(String url, int position) {
                finish();
            }
        });
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        imageShowView.setLayoutParams(params);
        setContentView(imageShowView);
        imageShowView.addImageList(allImages, index);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
}
